package com.zsc.boot.utils;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.HashSet;
import java.util.Optional;
import java.util.Set;

/**
 * json数组转set集合工具类
 */
public class JsonToStringUtils {

    /**
     * 将字符串json数组转成Long类型的set集合
     * @param jsonList
     * @return
     */
    public static Set<Long> stringJsonListToSet(String jsonList){
        Set<Long> set = new Gson().fromJson(jsonList, new TypeToken<Set<Long>>() {
        }.getType());

        return Optional.ofNullable(set).orElse(new HashSet<>());
    }

    public static Set<String> stringTagsJsonListToSet(String jsonList){
        Set<String> set = new Gson().fromJson(jsonList, new TypeToken<Set<String>>() {
        }.getType());

        return Optional.ofNullable(set).orElse(new HashSet<>());
    }
}
